package com.codervibe.server.Impl;

import com.codervibe.mapper.UserMapper;
import com.codervibe.model.User;
import com.codervibe.server.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.codervibe.utils.MD5Utils.code;

@Service("UserService")
public class UserServiceImpl implements UserService {
    Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Resource
    private UserMapper userMapper;

    /**
     * 查询所有用户信息
     *
     * @return userList
     */
    @Override
    public List<User> selectUserAll() {
        return userMapper.selectUserAll();
    }

    /**
     * 添加用户信息列表
     *
     * @param userList
     * @return boolean
     */
    @Override
    public void addList(List<User> userList) {
        for (User user : userList) {
            user.setPassword(code(user.getPassword()));
            userMapper.addList(user);
        }

    }

    /**
     * 使用id 查询
     *
     * @param id
     * @return
     */
    @Override
    public List<User> selectUserByid(String id) {
        List<User> user = userMapper.selectUserByid(id);
        return user;
    }


}
